<%--
  Created by IntelliJ IDEA.
  User: 姜
  Date: 2022/2/15
  Time: 17:46
  To change this template use File | Settings | File Templates.
--%>
<%@ page isELIgnored="false" contentType="text/html;charset=UTF-8" pageEncoding="UTF-8" language="java" %>
<%@ taglib uri="http://java.sun.com/jsp/jstl/core" prefix="c" %>
<%@ taglib uri="http://java.sun.com/jsp/jstl/fmt"  prefix="fmt"%>
<!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd">
<html>
<head>
    <meta http-equiv="Content-Type" content="text/html; charset=UTF-8">
    <title>Title</title>
    <script type="text/javascript" src="/js/jquery-1.4.4.min.js"></script>
    <script type="text/javascript" src="/js/jquery.form.min.js"></script>
</head>
<body>
<button onclick="getUsers()">查询操作</button>
<button onclick="saveUser()">新增操作</button>
<button onclick="putUser()">修改操作</button>
<button onclick="delUser()">删除操作</button>


</body>
<script type="text/javascript">

    function getUsers(){  // 发送get请求
        $.ajax({
            url:'http://localhost:8080/rest/users',
            type:'get',
            success:function(ret){
                console.log(ret);
            }
        });
    }

    function saveUser(){ // 发送更新请求 （增加请求发送方式也是如此）
        var user = {username:"shine",age:20,"birthday":"2020/12/12"};

        $.ajax({
            url:'http://localhost:8080/rest/users',
            type:'post',
            contentType:"application/json",//声明请求参数类型为 json
            data:JSON.stringify(user),// 转换js对象成json
            success:function(ret){
                console.log(ret);
            }
        });
    }

    function putUser(){ // 发送更新请求 （增加请求发送方式也是如此）
        var user = {id:1, username:"shine",age:20,"birthday":"2020/12/12"};

        $.ajax({
            url:'http://localhost:8080/rest/users',
            type:'put',
            contentType:"application/json",//声明请求参数类型为 json
            data:JSON.stringify(user),// 转换js对象成json
            success:function(ret){
                console.log(ret);
            }
        });
    }

    function delUser(){  // 发送删除请求
        var id = 1;
        //  /rest/users?id=1
        $.ajax({
            url:'http://localhost:8080/rest/users/1',
            type:'delete',
            success:function(ret){
                console.log(ret);
            }
        });
    }


</script>

</html>

